var _Page;

function _defineProperty(a, t, e) {
    return t in a ? Object.defineProperty(a, t, {
        value: e,
        enumerable: !0,
        configurable: !0,
        writable: !0
    }) : a[t] = e, a;
}

var app = getApp();

Page((_defineProperty(_Page = {
    data: {
        cardid: 0,
        _is_load: !0
    },
    onLoad: function(a) {
        var t = this, e = a.card_id;
        t.setData({
            cardId: e
        }), app.util.request({
            url: "entry/wxapp/GetCard",
            data: {
                m: "bbyscm_card",
                cardid: e
            },
            success: function(a) {
                0 == a.data.errno && 0 == a.data.data && wx.showModal({
                    title: "你还没有创建名片，不能发布广告",
                    content: "你还没有创建名片，不能发布广告",
                    showCancel: !1,
                    success: function() {
                        wx.navigateTo({
                            url: "../../card/edit/card-edit"
                        });
                    }
                }), t.setData({
                    card_info: a.data.data,
                    cardid: a.data.data.id,
                    openid: a.data.data.openid,
                    cardname: a.data.data.cardname
                });
            }
        }), app.util.request({
            url: "entry/wxapp/Setup",
            data: {
                m: "bbyscm_card"
            },
            success: function(a) {
                t.setData({
                    setup: a.data.data,
                    apikey: a.data.data.apikey
                });
            }
        }), app.util.request({
            url: "entry/wxapp/GetWords",
            data: {
                m: "bbyscm_card",
                cardid: e
            },
            success: function(a) {
                t.setData({
                    words: a.data.data,
                    wordsid: a.data.data.id,
                    day: Math.floor(a.data.data.syts / 86400),
                    hour: Math.floor((a.data.data.syts - 24 * Math.floor(a.data.data.syts / 86400) * 3600) / 3600)
                });
            }
        }), app.util.request({
            url: "entry/wxapp/GetGunsetup",
            data: {
                m: "bbyscm_card"
            },
            success: function(a) {
                t.setData({
                    gunsetup: a.data.data,
                    _is_load: !1
                });
            }
        });
    },
    onShareAppMessage: function() {},
    onReady: function() {},
    onShow: function() {
        var t = this;
        app.util.getUserInfo(function(a) {
            t.setData({
                userInfo: a
            });
        });
    },
    gunsetups: function(a) {
        a.target.dataset.id;
        this.setData({
            condition: !this.data.condition,
            days: a.target.dataset.days,
            coll: a.target.dataset.coll
        });
    },
    gunpayopen: function(a) {
        var t = this;
        0 < t.data.coll - t.data.card_info.money ? this.setData({
            pay_coll: t.data.coll,
            days: t.data.days,
            name: a.detail.value.name,
            form_id: a.detail.formId,
            bupay_coll: (t.data.coll - t.data.card_info.money).toFixed(2),
            pay_term: "postCard",
            payopen: !0
        }) : this.setData({
            pay_coll: t.data.coll,
            days: t.data.days,
            name: a.detail.value.name,
            form_id: a.detail.formId,
            bupay_coll: (0).toFixed(2),
            pay_term: "postCard",
            payopen: !0
        });
    },
    checkboxChange: function(a) {
        var t = this;
        a.detail.value[0] ? 0 < t.data.pay_coll - a.detail.value[0] ? t.setData({
            bupay_coll: (t.data.pay_coll - a.detail.value[0]).toFixed(2)
        }) : t.setData({
            bupay_coll: (0).toFixed(2)
        }) : t.setData({
            bupay_coll: t.data.pay_coll
        });
    },
    paycloes: function(a) {
        this.setData({
            payopen: !1
        });
    },
    postCard: function(a) {
        var t = this;
        t.setData({
            btn_disabled: !0,
            submitIsLoading: !0,
            payopen: !1
        }), JSON.stringify(a.detail.value);
        var e = t.data.formId, o = t.data.cardid, s = t.data.wordsid, d = t.data.name, n = t.data.cardname, c = t.data.days, i = t.data.bupay_coll, l = t.data.pay_coll - i;
        return o ? d ? c ? void (0 < i ? (t.setData({
            pay: !0
        }), app.util.request({
            url: "entry/wxapp/Pay",
            data: {
                m: "bbyscm_card",
                cost: i,
                days: c,
                id: s
            },
            method: "POST",
            success: function(a) {
                wx.requestPayment({
                    timeStamp: a.data.timeStamp,
                    nonceStr: a.data.nonceStr,
                    package: a.data.package,
                    signType: a.data.signType,
                    paySign: a.data.paySign,
                    success: function(a) {
                        console.log("支付成功", a), t.setData({
                            Msg: a.errMsg,
                            pay: !1
                        }), "requestPayment:ok" == t.data.Msg && (wx.showToast({
                            title: "提交中...",
                            icon: "loading",
                            duration: 1e4
                        }), app.util.request({
                            url: "entry/wxapp/PostWordspay",
                            data: {
                                m: "bbyscm_card",
                                cardid: o,
                                wordsid: s,
                                pay_class: 1,
                                days: c,
                                coll: i,
                                yepay_coll: l
                            },
                            method: "POST"
                        }), app.util.request({
                            url: "entry/wxapp/PostWords",
                            data: {
                                m: "bbyscm_card",
                                cardid: o,
                                wordsid: s,
                                pay_class: 1,
                                name: d,
                                days: c,
                                yepay_coll: l
                            },
                            method: "POST",
                            success: function(a) {
                                0 == a.data.errno ? (app.util.request({
                                    url: "entry/wxapp/message1",
                                    data: {
                                        m: "bbyscm_card",
                                        openid: t.data.card_info.openid,
                                        form_id: e,
                                        pay_class: 1,
                                        pay_classid: s,
                                        coll: i,
                                        days: c,
                                        cardname: n,
                                        page: "pages/user/index/index"
                                    },
                                    success: function(a) {
                                        console.log("模板消息发送成功"), console.log(a), wx.reLaunch({
                                            url: ""
                                        });
                                    }
                                }), wx.showModal({
                                    title: "提示",
                                    content: "提交成功",
                                    showCancel: !1,
                                    success: function(a) {
                                        wx.navigateBack();
                                    }
                                })) : wx.showModal({
                                    title: "提示",
                                    content: a.data.message,
                                    showCancel: !1,
                                    success: function(a) {
                                        a.confirm && console.log("用户点击确定");
                                    }
                                });
                            },
                            fail: function(a) {
                                wx.showModal({
                                    title: "提示",
                                    content: a.data.message,
                                    showCancel: !1,
                                    success: function(a) {
                                        a.confirm && console.log("用户点击确定");
                                    }
                                });
                            },
                            complete: function() {
                                wx.hideToast();
                            }
                        }));
                    },
                    fail: function(a) {
                        console.log("5", a), t.setData({
                            pay: !1,
                            btn_disabled: !1,
                            submitIsLoading: !1
                        }), wx.showToast({
                            title: "支付失败",
                            duration: 1e3
                        });
                    }
                });
            }
        })) : (app.util.request({
            url: "entry/wxapp/PostWordspay",
            data: {
                m: "bbyscm_card",
                cardid: o,
                wordsid: s,
                pay_class: 1,
                days: c,
                coll: i,
                yepay_coll: l
            },
            method: "POST"
        }), app.util.request({
            url: "entry/wxapp/PostWords",
            data: {
                m: "bbyscm_card",
                cardid: o,
                wordsid: s,
                pay_class: 1,
                name: d,
                days: c,
                yepay_coll: l
            },
            method: "POST",
            success: function(a) {
                0 == a.data.errno && wx.showModal({
                    title: "提示",
                    content: "提交成功",
                    showCancel: !1,
                    success: function(a) {
                        wx.navigateBack();
                    }
                });
            }
        }))) : (wx.showModal({
            title: "提示",
            content: "请选择天数",
            showCancel: !1,
            success: function(a) {
                a.confirm && console.log("用户点击确定"), t.setData({
                    btn_disabled: !1,
                    submitIsLoading: !1
                });
            }
        }), !1) : (wx.showModal({
            title: "提示",
            content: "没有填写广告内容",
            showCancel: !1,
            success: function(a) {
                a.confirm && console.log("用户点击确定"), t.setData({
                    btn_disabled: !1,
                    submitIsLoading: !1
                });
            }
        }), !1) : (wx.showModal({
            title: "提示",
            content: "获取信息失败",
            showCancel: !1,
            success: function(a) {
                a.confirm && console.log("用户点击确定"), t.setData({
                    btn_disabled: !1,
                    submitIsLoading: !1
                });
            }
        }), !1);
    },
    onHide: function() {},
    onUnload: function() {},
    onPullDownRefresh: function() {},
    onReachBottom: function() {}
}, "onShareAppMessage", function() {}), _defineProperty(_Page, "open", function() {
    this.setData({
        condition: !this.data.condition
    });
}), _Page));